package com.nulldev.util.concurrency.threadIt.v4.utils.threadit_on_jre;

import com.nulldev.util.JVM.Exceptions;
import com.nulldev.util.JVM.JVM;
import com.nulldev.util.JVM.reflections.Reflections;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutorManager;
import com.nulldev.util.manage.nullUtil;

public class TIOnJRE {

	private static boolean __init;

	public static void apply() {
		if (__init)
			return;
		if (JVM.version() >= 12f || nullUtil.IS_ANDROID_BUILD) {
			System.out.println("[ti!OnJRE] Unsupported JRE found, skipping.");
			__init = true;
			return;
		}
		try {
			final Reflections ref = Reflections.use("java.util.concurrent.CompletableFuture");
			ref.assignVar("asyncPool", ExecutorManager.get());
			__init = true;
			System.out.println("[ti!OnJRE] Hooked successfully.");
		} catch (Throwable tx) {
			__init = true;
			System.err.println("[ti!OnJRE] Failed to hook.");
			System.err.println(Exceptions.toString(tx));
		}
	}

	public static boolean isApplied() {
		return __init;
	}
}
